package com.meng.system.domain.vo;


import com.meng.system.enums.ErrorEnum;

import java.io.Serializable;

/**
 * @author: Xu Meng
 * @program: minions-cloud
 * @create: 2021-01-18 16:07
 **/
public class ResponseVO<T> implements Serializable {

    private static final long serialVersionUID = -1481286800170822268L;
    // 错误码
    private int code;
    // 错误信息
    private String message;
    // 返回数据
    private T data;

    public ResponseVO() {
        super();
    }

    public ResponseVO(ErrorEnum errorEnum) {
        this(errorEnum, null);
    }

    public ResponseVO(ErrorEnum errorEnum, T data) {
        this.code = errorEnum.getErrorCode();
        this.message = errorEnum.getMessage();
        this.data = data;
    }

    public ResponseVO(int errorCode, String message) {
        this.code = errorCode;
        this.message = message;
    }
    public ResponseVO(T data) {
        this(ErrorEnum.SUCCESS.getErrorCode(), null, data);
    }

    public ResponseVO(int errorCode, String message, T data) {
        this.code = errorCode;
        this.message = message;
        this.data = data;
    }

    public static ResponseVO<?> result(ErrorEnum enums, Object data){
        ResponseVO<Object> result = new ResponseVO<>();
        result.setCode(enums.getErrorCode());
        result.setData(data);
        result.setMessage(enums.getMessage());
        return result;
    }

    public static ResponseVO<?> result(ErrorEnum enums){
        ResponseVO<Object> result = new ResponseVO<>();
        result.setCode(enums.getErrorCode());
        result.setMessage(enums.getMessage());
        return result;
    }

    public static ResponseVO<?> error(ErrorEnum enums){
        ResponseVO<Object> result = new ResponseVO<>();
        result.setCode(enums.getErrorCode());
        result.setMessage(enums.getMessage());
        return result;
    }

    public int getCode() {
        return code;
    }

    public void setCode(int code) {
        this.code = code;
    }

    public String getMessage() {
        return message;
    }

    public void setMessage(String message) {
        this.message = message;
    }

    public T getData() {
        return data;
    }

    public void setData(T data) {
        this.data = data;
    }
}

